/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.machineryrental.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Marian Lorenc, 374122
 */
@Entity
public class Customer implements Serializable {

    /**
     * Unique identifier of Customer
     */
    @Id
    @GeneratedValue
    private long id;
    /**
     * Contains first name of customer
     */
    @Column(length = 100, nullable = false)
    private String firstName;
    /**
     * Contains last name of customer
     */
    @Column(length = 100, nullable = false)
    private String lastName;
    /**
     * Contains email of customer. Email is unique.
     */
    @Column(length = 100, nullable = false, unique = true)
    private String email;
    /**
     * List of all rentals of customer.
     */
    @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY)
    private List<Rental> rentals;
    /**
     * Customers phone number.
     */
    @Column(nullable = false)
    private String phone;
    /**
     * Customers address.
     */
    @Column(nullable = false)
    @Embedded
    private Address address;
    /**
     * Type of customer.
     */
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private CustomerTypeEnum customerType;
    /**
     * Value added tax identification number of customer.
     */
    private String vatNumber;
    /**
     * Customers company number.
     */
    private String companyNumber;

    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * @return the address
     */
    public Address getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(Address address) {
        this.address = address;
    }

    /**
     * @return the customerType
     */
    public CustomerTypeEnum getCustomerType() {
        return customerType;
    }

    /**
     * @param customerType the customerType to set
     */
    public void setCustomerType(CustomerTypeEnum customerType) {
        this.customerType = customerType;
    }

    /**
     * @return the VATNumber
     */
    public String getVatNumber() {
        return vatNumber;
    }

    /**
     * @param VATNumber the VATNumber to set
     */
    public void setVatNumber(String vatNumber) {
        this.vatNumber = vatNumber;
    }

    /**
     * @return the companyNumber
     */
    public String getCompanyNumber() {
        return companyNumber;
    }

    /**
     * @param companyNumber the companyNumber to set
     */
    public void setCompanyNumber(String companyNumber) {
        this.companyNumber = companyNumber;
    }

    /**
     * Returns unique identifier of customer.
     *
     * @return Unique identifier of customer
     */
    public long getId() {
        return id;
    }

    /**
     * Sets unique identifier of customer
     *
     * @param id Unique identifier
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Returns rentals of customer.
     *
     * @return Rentals of customer.
     */
    public List<Rental> getRentals() {
        return rentals;
    }

    /**
     * Sets list of rentals of customer.
     *
     * @param rentals List of rentals of customer
     */
    public void setRentals(List<Rental> rentals) {
        this.rentals = rentals;
    }

    /**
     * Returns first name of customer
     *
     * @return Customer's first name.
     */
    public String getFirstName() {
        return this.firstName;
    }

    /**
     * Sets first name of customer.
     *
     * @param firstName Customer's fist name
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Return last name of customer
     *
     * @return Customer's last name.
     */
    public String getLastName() {
        return this.lastName;
    }

    /**
     * Sets last name of customer
     *
     * @param lastName Customer's last name
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Returns unique email of customer.
     *
     * @return Customer's email.
     */
    public String getEmail() {
        return this.email;
    }

    /**
     * Sets email of customer
     *
     * @param email Customer's email.
     */
    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return this.lastName + " " + this.firstName + " ("
                + this.email + ")";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (id ^ (id >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) obj;
        return id == other.id;
    }
}
